package com.gmail.at.dengtooling.packets;

import com.gmail.at.dengtooling.util.Constant;
import com.gmail.at.dengtooling.util.Type;

/**
 * 
 * @author linybin7
 * 2012-3-4
 */
public class Packets {
	private int		packetLens;
	private int		paddingLens;
	private byte[]	contents;
	private byte[]	paddings;
	private byte[]	macs;
	private int		packetType;
	
	
	public Packets(byte[] b) {
		int offset=0;
		byte[] cLens=new byte[4];
		System.arraycopy(b, offset, cLens, 0, 4);
		this.packetLens=Type.bytes2int(cLens);
		offset+=4;
		
		byte[] pLens=new byte[1];
		System.arraycopy(b, offset, pLens, 0, 1);
		offset+=1;
		this.paddingLens=pLens[0] & 0xff;
		
		System.arraycopy(b, offset, contents, 0, packetLens-paddingLens);
		offset+=packetLens-paddingLens;
		
		System.arraycopy(b, offset, contents, 0, paddingLens);
		offset+=paddingLens;
		
		System.arraycopy(b, offset, macs, 0, b.length-offset);
		
		byte type=pLens[0];
		this.packetType=type & 0xff;
	}


	public int getPacketLens() {
		return packetLens;
	}


	public void setPacketLens(int packetLens) {
		this.packetLens = packetLens;
	}


	public int getPaddingLens() {
		return paddingLens;
	}


	public void setPaddingLens(int paddingLens) {
		this.paddingLens = paddingLens;
	}


	public byte[] getContents() {
		return contents;
	}


	public void setContents(byte[] contents) {
		this.contents = contents;
	}


	public byte[] getPaddings() {
		return paddings;
	}


	public void setPaddings(byte[] paddings) {
		this.paddings = paddings;
	}


	public byte[] getMacs() {
		return macs;
	}


	public void setMacs(byte[] macs) {
		this.macs = macs;
	}


	public int getPacketType() {
		return packetType;
	}
	
	public String getPacketName(){
		return Constant.packetsNames[this.packetType];
	}

	public void setPacketType(int packetType) {
		this.packetType = packetType;
	}
}